using System.Windows.Forms;
using NUnit.Framework;

namespace ShadeTree.Binding.Tests
{
    [TestFixture]
    public class ScreenStateTester
    {
        #region Setup/Teardown

        [SetUp]
        public void SetUp()
        {
        }

        #endregion

        [Test]
        public void ContainsControl()
        {
            var control1 = new Control();
            var control2 = new Control();
            var control3 = new Control();
            var control4 = new Control();

            var set = new ControlSet();
            set.Add(control1);
            set.Add(control4);

            set.Contains(control1).ShouldBeTrue();
            set.Contains(control2).ShouldBeFalse();
            set.Contains(control3).ShouldBeFalse();
            set.Contains(control4).ShouldBeTrue();
        }

        [Test]
        public void ControlSetDoesNotAddDuplicates()
        {
            var control1 = new Control();
            var control2 = new Control();
            var control3 = new Control();
            var control4 = new Control();

            var set = new ControlSet();
            set.Add(control1);
            set.Add(control1);
            set.Add(control1);

            set.Count.ShouldEqual(1);

            set.Add(control2);
            set.Add(control2);

            set.Count.ShouldEqual(2);
        }

        [Test]
        public void The_DisableAllButScreenState_will_disable_all_controls_except_the_ones_that_it_governs()
        {
            var control1 = new Control();
            var control2 = new Control();
            var control3 = new Control();
            var control4 = new Control();

            var state = new DisableAllButScreenState();
            state.Enable(control2, control3);

            state.IsControlEnabled(control1).ShouldBeFalse();
            state.IsControlEnabled(control2).ShouldBeTrue();
            state.IsControlEnabled(control3).ShouldBeTrue();
            state.IsControlEnabled(control4).ShouldBeFalse();
        }

        [Test]
        public void The_NormalScreenState_looks_in_its_internal_collection_and_the_All_collection()
        {
            var control1 = new Control();
            var control2 = new Control();
            var control3 = new Control();
            var control4 = new Control();

            var set = new ControlSet();
            set.Add(control1);
            set.Add(control4);

            var state = new NormalScreenState(set);
            state.Enable(control2);

            state.IsControlEnabled(control1).ShouldBeFalse();
            state.IsControlEnabled(control2).ShouldBeTrue();
            state.IsControlEnabled(control3).ShouldBeTrue();
            state.IsControlEnabled(control4).ShouldBeFalse();
        }
    }
}